package com.sinosoft.weixin.controller;

import com.sinosoft.weixin.config.InterfaceAdapterConfig;
import com.sinosoft.weixin.controller.dto.RequestDTO;
import com.sinosoft.weixin.controller.dto.RequestHeadDTO;
import com.sinosoft.weixin.controller.dto.request.CheckWorkNumDTO;
import com.sinosoft.weixin.controller.vo.Vo;
import com.sinosoft.weixin.service.MessageService;
import com.sinosoft.weixin.utils.RandomUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by huzhengying on 2017/11/9.
 */
@RestController
@RequestMapping("test")
public class TestController {
    private static Logger logger = LogManager.getLogger(TestController.class);
    @Autowired
    InterfaceAdapterConfig interfaceAdapterConfig;
    @Autowired
    MessageService messageService;

    @RequestMapping("testSendMessage")
    public Object test1(HttpServletRequest request){
        Map<String,String> map = new HashMap<>();
        map.put("verificationCode","1234");
        messageService.sendMessage("test","GCS0001","13921146230",map);
        return Vo.succ();
    }

    @RequestMapping("login")
    public Object login(){
        Subject subject = SecurityUtils.getSubject();
        SecurityUtils.getSubject().getSession().setTimeout(-1);
        UsernamePasswordToken token = new UsernamePasswordToken("1","2");
        subject.login(token);
        return Vo.succ("登陆成功");
    }

    @RequestMapping("testRequestDTO")
    public Object testRequestDTO(){
        RequestHeadDTO requestHeadDTO = new RequestHeadDTO("1","213");
        CheckWorkNumDTO checkWorkNumDTO = new CheckWorkNumDTO();
        checkWorkNumDTO.setMobile("12311112222");
        checkWorkNumDTO.setAgentCode("808080");
        checkWorkNumDTO.setName("啊哈哈");
        RequestDTO requestDTO = new RequestDTO(requestHeadDTO,checkWorkNumDTO);
        return requestDTO;
    }

    @RequestMapping("test")
    public Object test(){
        return interfaceAdapterConfig.getContextUrl("test");
    }
}
